<?
include_once 'lib/facebook.php';
include_once 'includes/config.php';
include_once 'includes/dbconnect.php';
include_once 'tableObjects/TblMember.php';
include_once 'includes/function.php';
header('p3p: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"');

function detect_mobile() {
    if (preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|sagem|sharp|sie-|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
        return true;
    else
        return false;
}

if (detect_mobile() == true) {
    ?>
    <script>top.location.href='<?= MOBILE_APP_URL ?>'</script>
    <?
    die();
}


if (!empty($_GET['from_mobile'])) {
    echo "from mobile";
    ?>
    <script>top.location.href='<?= MOBILE_APP_URL ?>'</script>
    <?
    die();
}

$_SESSION['pid'] = 'instruction';

checkFbAuth();

if (SANDBOX_MODE == 0) {
    $isFan = $facebook->api(array(
        "method" => "pages.isFan",
        "page_id" => FACEBOOK_PAGE_ID,
        "uid" => $_SESSION['fb_id']
            ));
} else {
    $isFan = true;
}

$isFan = True;

if ($isFan === TRUE) {
    include_once 'includes/header.php';

    if (SANDBOX_MODE == 0) {
        ?>
        <script>

            try{
                if(window.top.location.toString().indexOf("http://www.facebook.com") != 0 && window.top.location.toString().indexOf("https://www.facebook.com") != 0){
                    window.top.location = "<?= FACEBOOK_PAGE_TAB_URL ?>";
                }		
            }catch(err){}			
        </script>
    <? } ?>

    <link type="text/css" href="includes/css/jquery.jscrollpane.css" rel="stylesheet" media="all" />

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript" src="includes/js/jquery.gchart.min.js"></script>
    <script type="text/javascript" src="includes/js/jquery.jscrollpane.min.js"></script>
    <script type="text/javascript" src="includes/js/jquery.mousewheel.js"></script>
    <script type="text/javascript" src="includes/js/jquery.imagetick.min.js"></script>
    <script type="text/javascript" src="includes/js/jquery.validate.js"></script>

    <script language="javascript">
                                                                                                                                                                                                                                                                                                                                
        function streamPublishPoll(msg,pid,hrefTitle, userPrompt)
        {
            var yes_percent = $('#question'+pid).data("yes-percent"); 
            msg=yes_percent+msg;
            FB.init({
                appId  : '<?= trim(FACEBOOK_APP_ID) ?>',
                status : true, // check login status
                cookie : true, // enable cookies to allow the server to access the session
                xfbml  : true,  // parse XFBML
                oauth  : true // enable OAuth 2.0
            });
            FB.ui(
            {
                method: 'stream.publish',
                message: msg,
                display: 'dialog',
                attachment: {
                    name: '<?= str_replace("'", "\\'", FACEBOOK_APP_NAME) ?>',
                    caption: '',
                    description: (msg),
                    href:'<?= FACEBOOK_PAGE_TAB_URL ?>',                  
                    media: [{
                            type: 'image',
                            src: 'http://www.dciapp.com/maybank/whats-your-take/fb-app/images/logo2.gif',
                            href:'<?= FACEBOOK_PAGE_TAB_URL ?>'
                        }]
                },
                action_links: [
                    {
                        text: hrefTitle, 
                        href: '<?= FACEBOOK_PAGE_TAB_URL ?>'
                    }
                ],
                user_prompt_message: userPrompt
            },
            function(response) {
                if (response && response.post_id){
                    $.ajax({
                        type: "post",
                        url: 'update_share.php',
                        data: "uid=<?= $_SESSION['fb_id'] ?>&share_msg="+msg+"&share_type=poll&share_with=wall_share&pid="+pid,
                        success: function(data) {  
                            $('#divMsg').html(data);
                        }
                    });
                                                                                                                                                                                                                                                                                                                                            
                }
                                                                                                                                                                                                                                                                                                                              
            }
        );
        }
                                                                                                                                                                                                                                                                                                                
        function streamPublishPollCheck(pid,hrefTitle, userPrompt)
        {
            var com_percent = $('#question'+pid).data("com-percent"); 
            var mobile_percent = $('#question'+pid).data("mobile-percent"); 
            var tab_percent = $('#question'+pid).data("tab-percent"); 
                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                
            var msg="Devices used to access digital banking: "+com_percent+"% Computer, "+mobile_percent+"% Mobile Phone, "+tab_percent+"% Tablets.";
                                                                                                                                                                                                                                                                                                                
            FB.init({
                appId  : '<?= trim(FACEBOOK_APP_ID) ?>',
                status : true, // check login status
                cookie : true, // enable cookies to allow the server to access the session
                xfbml  : true,  // parse XFBML
                oauth  : true // enable OAuth 2.0
            });
            FB.ui(
            {
                method: 'stream.publish',
                message: msg,
                display: 'dialog',
                attachment: {
                    name: '<?= str_replace("'", "\\'", FACEBOOK_APP_NAME) ?>',
                    caption: '',
                    description: (msg),
                    href:'<?= FACEBOOK_PAGE_TAB_URL ?>',                  
                    media: [{
                            type: 'image',
                            src: 'http://www.dciapp.com/maybank/whats-your-take/fb-app/images/logo2.gif',
                            href:'<?= FACEBOOK_PAGE_TAB_URL ?>'
                        }]
                },
                action_links: [
                    {
                        text: hrefTitle, 
                        href: '<?= FACEBOOK_PAGE_TAB_URL ?>'
                    }
                ],
                user_prompt_message: userPrompt
            },
            function(response) {
                if (response && response.post_id){
                    $.ajax({
                        type: "post",
                        url: 'update_share.php',
                        data: "uid=<?= $_SESSION['fb_id'] ?>&share_msg="+msg+"&share_type=poll&share_with=wall_share&pid="+pid,
                        success: function(data) {  
                            $('#divMsg').html(data);
                        }
                    });
                                                                                                                                                                                                                                                                                                                                            
                }
                                                                                                                                                                                                                                                                                                                              
            }
        );
        }
                                                                                                                                                                                                                                                                                                                            
        function share_twitter_poll(content,pid){
            var yes_percent = $('#question'+pid).data("yes-percent"); 
            content = yes_percent +""+content;
            window.open('http://twitter.com/home?status='+content,'<?= str_replace("'", "\\'", FACEBOOK_APP_NAME) ?>','status=0,width=620,height=350,top=0,left=0');
                                                                                                                                                                                                                                                                                                        
            content = content.replace("'","\\'");
                                                                                                                                                                                                                                                                                                        
            setTimeout("updateTweeterSharePoll('"+content+"','"+pid+"')",1000);	  
        }
                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                     
        function share_twitter_poll_check(content,pid){
            var com_percent = $('#question'+pid).data("com-percent"); 
            var mobile_percent = $('#question'+pid).data("mobile-percent"); 
            var tab_percent = $('#question'+pid).data("tab-percent"); 
                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                
            var content="Devices used to access digital banking: "+com_percent+" percent Computer, "+mobile_percent+" percent Mobile Phone, "+tab_percent+" percent Tablets. http://goo.gl/fBd3t";
                                                                                                                                                                                                                                                                                                    
            window.open('http://twitter.com/home?status='+content,'<?= str_replace("'", "\\'", FACEBOOK_APP_NAME) ?>','status=0,width=620,height=350,top=0,left=0');
                                                                                                                                                                                                                                                                                                        
            content = content.replace("'","\\'");
                                                                                                                                                                                                                                                                                                        
            setTimeout("updateTweeterSharePoll('"+content+"','"+pid+"')",1000);	  
        }
                                                                                                                                                                                                                                                                                                

        function updateTweeterSharePoll(content,pid)
        {   
                                                                                                                                                                                                                                                                                            
            $.ajax({
                type: "post",
                url: "update_share.php",
                data: "uid=<?= $_SESSION['fb_id'] ?>&share_msg="+content+"&share_type=tw_poll&pid="+pid,
                success: function(data) {  
                    //$('#divMsg').html(data);
                }
            });
        }
                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
    </script>
    <div id="divComment">

    </div>

    <script type="text/javascript" src="includes/js/jquery.cycle.all.js"></script>

    <!--  initialize the slideshow when the DOM is ready -->

    <table width="800" height="500" cellpadding="0" cellspacing="0" style="border:1px solid #f5f5f5"  >

        <tr>
            <Td height="365" align="center">

                <script type="text/javascript">
                    $(function() {
                        $('#slide_banner').cycle({
                            fx: 'scrollRight' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
                        });
                    });
                </script>
                <div id="slide_banner" >                                
                    <a href=""><img src="images/text_usedigitalbanking.png" border="0" /></a>                                
                </div>
            </td>
            <td width="300" style="vertical-align: top;height:800px" rowspan="2">
                <table width="100%" >
                    <tr>
                        <td height="50" bgcolor="#fec832" align="center">
                            <img src="images/text_haveyoursay.png">
                        </td>
                    </tr>
                    <tr>
                        <Td width="100%" style="background-color:#cccccc">
                            <script>
                                $().ready(function() {
                                    $("#frm1").validate({
                                        invalidHandler: function(form, validator) {
                                            var errors = validator.numberOfInvalids();
                                                                                                   
                                            if (errors) {
                                                var message = '<font class=msg_failed>Please answer all questions</font>';
                                                $("#errMsg").html(message);
                                                                                                                            
                                            } else {
                                                $("div.error").hide();
                                            }
                                        },
                                        rules: {
                                            checkBox1 : "required",
                                            checkBox2 : "required",
                                            checkBox3 : "required",
                                            checkBox4 : "required",
                                            checkBox6 : "required",
                                            checkBox7 : {
                                                required: true,
                                                minlength: 1
                                            }
                                        },
                                        messages: {
                                            checkBox1 : "",
                                            checkBox2 : "",
                                            checkBox3 : "",
                                            checkBox4 : "",
                                            checkBox6 : "",
                                            checkBox7 : ""  
                                        },
                                        wrapper: "div"
                                                                                    		

                                    });
                                                                                    	
                                });
                            </script>

                            <form action="submit_process.php" method="post" id="frm1">

                                <script type="text/javascript" src="includes/js/jquery.imagetick.min.js"></script>

                                <script >
                                    (function($){

                                        $.fn.imageTick = function(options) {

                                            var defaults = {
                                                tick_image_path: "images/radio.gif",
                                                no_tick_image_path: "no_images/radio.gif",
                                                image_tick_class: "ticks_" + Math.floor(Math.random()),
                                                hide_radios_checkboxes: false
                                            };

                                            var opt = $.extend(defaults, options);

                                            this.each(function(){

                                                var obj = $(this);
                                                var type = obj.attr('type'); // radio or checkbox

                                                var tick_image_path = typeof opt.tick_image_path == "object" ?
                                                    opt.tick_image_path[this.value] || opt.tick_image_path["default"] :
                                                    opt.tick_image_path;

                                                var no_tick_image_path = function(element_id) {
                                                    var element = document.getElementById(element_id) || { value: "default" };
                                                    return typeof opt.no_tick_image_path == "object" ?
                                                        opt.no_tick_image_path[element.value] || opt.no_tick_image_path["default"]:
                                                        opt.no_tick_image_path;
                                                }

                                                // hide them and store an image background
                                                var id = obj.attr('id');
                                                var imgHTML = '<img src="' + no_tick_image_path(id) + '" alt="no_tick" class="' + opt.image_tick_class + '" id="tick_img_' + id + '" />';

                                                obj.before(imgHTML);
                                                if(!opt.hide_radios_checkboxes){
                                                    obj.css('display','none');
                                                }

                                                // if something has a checked state when the page was loaded
                                                if(obj.attr('checked')){
                                                    $("#tick_img_" + id).attr('src', tick_image_path);
                                                }

                                                // if we're deadling with radio buttons
                                                if(type == 'radio'){

                                                    // if we click on the image
                                                    $("#tick_img_"+id).click(function(){
                                                        $("." + opt.image_tick_class).each(function() {
                                                            var r = this.id.split("_");
                                                            var radio_id = r.splice(2,r.length-2).join("_");
                                                            $(this).attr('src', no_tick_image_path(radio_id))
                                                        });
                                                        $("#" + id).trigger("click");
                                                        $(this).attr('src', tick_image_path);
                                                    });

                                                    // if we click on the label
                                                    $("label[for='" + id + "']").click(function(){
                                                        $("." + opt.image_tick_class).each(function() {
                                                            var r = this.id.split("_");
                                                            var radio_id = r.splice(2,r.length-2).join("_");
                                                            $(this).attr('src', no_tick_image_path(radio_id))
                                                        });
                                                        $("#" + id).trigger("click");
                                                        $("#tick_img_" + id).attr('src', tick_image_path);
                                                    });

                                                }

                                                // if we're deadling with checkboxes
                                                else if(type == 'checkbox'){

                                                    $("#tick_img_" + id).click(function(){
                                                        $("#" + id).trigger("click");
                                                        if($(this).attr('src') == no_tick_image_path(id)){
                                                            $(this).attr('src', tick_image_path);
                                                        }
                                                        else {
                                                            $(this).attr('src', no_tick_image_path(id));
                                                        }

                                                    });

                                                    // if we click on the label
                                                    $("label[for='" + id + "']").click(function(){
                                                        if($("#tick_img_" + id).attr('src') == no_tick_image_path(id)){
                                                            $("#tick_img_" + id).attr('src', tick_image_path);
                                                        }
                                                        else {
                                                            $("#tick_img_" + id).attr('src', no_tick_image_path(id));
                                                        }
                                                    });

                                                }

                                            });
                                        }

                                    })(jQuery);
                                                                                                                                    
                                                                                                                                  
                                </script>

                                <?
                                $check_voted = mysql_query("select is_voted from tbl_member where fb_id='" . $_SESSION['fb_id'] . "'");
                                $is_voted = mysql_result($check_voted, 0, "is_voted");



                                $get = mysql_query("select * from tbl_question order by order_id asc") or die(mysql_error());
                                $total_records = mysql_num_rows($get);
                                $no = 1;


                                while ($q = mysql_fetch_assoc($get)) {
                                    $question_id = $q['id'];
                                    if ($q['is_multiple'] == 0) {

                                        $got_result = 0;
                                        $get_yes = mysql_query("select count(*) as result from tbl_answer where answer='Y' and question_id='$question_id'");
                                        $get_no = mysql_query("select count(*) as result from tbl_answer where answer='N' and question_id='$question_id'");

                                        $total_yes = mysql_result($get_yes, 0, "result");
                                        $total_no = mysql_result($get_no, 0, "result");
                                        $yes_percent = $no_percent = 0;


                                        if ($total_yes > 0) {
                                            $yes_percent = number_format(($total_yes / ($total_yes + $total_no)) * 100, 0);
                                        }

                                        if ($total_no > 0) {
                                            $no_percent = number_format(($total_no / ($total_yes + $total_no)) * 100, 0);
                                        }

                                        $share_copy = str_replace("[percent]", "", $q['share_copy']);
                                        $share_copy_clean = str_replace("%", " percent", $share_copy);


                                        $get_user_answer = mysql_query("select * from tbl_answer where question_id='$question_id' and fb_id='" . $_SESSION['fb_id'] . "'");

                                        if (mysql_num_rows($get_user_answer) > 0) {
                                            if (mysql_result($get_user_answer, 0, "answer") == "Y") {
                                                $img_yes = "box_yes_checked";
                                                $img_no = "box_no";
                                            } else {
                                                $img_yes = "box_yes";
                                                $img_no = "box_no_checked";
                                            }
                                        } else {
                                            $yes_chk = "";
                                            $no_chk = "";
                                        }
                                        ?>

                                        <div id="question<?= $q['id'] ?>" data-yes-percent="<?= $yes_percent ?>" data-no-percent="<?= $no_percent ?>" ></div>
                                        <div style="padding-bottom:2px;">
                                            <table width="100%" height="100%"  cellpadding="0" cellspacing="0" style="background-color:#f1f1f1">
                                                <tr>
                                                    <td style="vertical-align: top;padding-right: 10px;padding-top:6px" colspan="2" >
                                                        <a href="javascript:share_twitter_poll('<?= str_replace("'", "\\'", rtrim($share_copy_clean)) ?> http://goo.gl/fBd3t','<?= $q['id'] ?>')"><img src="images/btn_twitter.png" style="float:right;margin-right: 2px" border="0"></a>                                        
                                                        <a href="javascript:streamPublishPoll('<?= str_replace("'", "\\'", $share_copy) ?>','<?= $q['id'] ?>', '<?= str_replace("'", "\\'", FACEBOOK_APP_NAME) ?>', '')" ><img src="images/btn_facebook.png" style="float:right;margin-right: 2px" border="0"></a>   
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" style="vertical-align: top;padding-top:5px" >
                                                        <table width="90%" align="center">
                                                            <Td style="vertical-align: top" width="3%"><b><?= $no ?>. </b></td>
                                                            <td align="left"><?= $q['question'] ?></td>

                                                        </table>

                                                    </td>
                                                </tr>
                                                <tr >
                                                    <td style="vertical-align: middle;padding-left: 10px" height="65">
                                                        <div id="divChart<?= $q['id'] ?>" style="width: 140px; height: 80px;">

                                                        </div>

                                                    </td>
                                                    <td width="120" style="float:right;display: block;padding-top:20px;padding-left: 10px">
                                                        <?
                                                        if ($is_voted == 0) {
                                                            ?>
                                                            <table>
                                                                <tr>
                                                                    <td><input type="radio"  id="checkYes<?= $q['id'] ?>" name="checkBox<?= $q['id'] ?>" value="Y_<?= $q['id'] ?>"></td>
                                                                    <td><label for="checkYes<?= $q['id'] ?>"><font class="poll_option">Yes</font></label></td>
                                                                </tr>
                                                                <tr>
                                                                    <td><input type="radio" id="checkNo<?= $q['id'] ?>" name="checkBox<?= $q['id'] ?>" value="N_<?= $q['id'] ?>"  ></td>
                                                                    <td><label for="checkNo<?= $q['id'] ?>"><font class="poll_option">No</font></label></td>
                                                                </tr>

                                                            </table>
                                                            <script>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
                                                                $("input[name='checkBox<?= $q['id'] ?>']").imageTick({ 
                                                                    tick_image_path: { 
                                                                        'Y_<?= $q['id'] ?>' : "images/checkbox_yellow_checked.png", 
                                                                        'N_<?= $q['id'] ?>' : "images/checkbox_black_checked.png"
                                                                    },
                                                                    no_tick_image_path: { 
                                                                        'Y_<?= $q['id'] ?>' : "images/checkbox_yellow_no_checked.png", 
                                                                        'N_<?= $q['id'] ?>' : "images/checkbox_black_no_checked.png"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                    }
                                                                });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                                            </script>
                                                            <?
                                                        } else {
                                                            $img_check_yes = "checkbox_yellow_no_checked.png";
                                                            $img_check_no = "checkbox_black_no_checked.png";

                                                            $get_result = mysql_query("select * from tbl_answer where fb_id='" . $_SESSION['fb_id'] . "' and question_id='" . $q['id'] . "'");

                                                            if (mysql_result($get_result, 0, "answer") == "Y") {
                                                                $img_check_yes = "checkbox_yellow_checked.png";
                                                            } else {
                                                                $img_check_no = "checkbox_black_checked.png";
                                                            }
                                                            ?>
                                                            <table>
                                                                <tr>
                                                                    <td><img src="images/<?= $img_check_yes ?>" style="float:left;margin-right: 4px" border="0"></td>
                                                                    <td><label for="checkYes<?= $q['id'] ?>"><font class="poll_option">Yes</font></label></td>
                                                                </tr>
                                                                <tr>
                                                                    <td><img src="images/<?= $img_check_no ?>"  style="float:left;margin-right:4px" border="0"></td>
                                                                    <td><label for="checkNo<?= $q['id'] ?>"><font class="poll_option">No</font></label></td>
                                                                </tr>

                                                            </table>
                                                        <? } ?>
                                                    </td>
                                                </tr>
                                                <Tr>
                                                    <Td style="height:10px">&nbsp;</td>
                                                </tr>


                                            </table>
                                        </div>

                                        <script>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                            var data = [$.gchart.series('2004', [<?= $total_yes ?>, <?= $total_no ?>])];
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                            data[0].color= ['#f9be20', '#000000'];
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
                                            $('#divChart<?= $q['id'] ?>').gchart({type: 'pie', series: data, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                dataLabels: ['<?= $yes_percent ?>%','<?= $no_percent ?>%'],
                                                backgroundColor : 'transparent',
                                                pieOrientation : 180
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                            }); 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
                                        </script>
                                        <?
                                    } else {

                                        $get_com = mysql_query("select count(*) as result from tbl_answer where answer='C' and question_id='$question_id'");
                                        $get_mobile = mysql_query("select count(*) as result from tbl_answer where answer='M' and question_id='$question_id'");
                                        $get_tab = mysql_query("select count(*) as result from tbl_answer where answer='T' and question_id='$question_id'");

                                        $total_com = mysql_result($get_com, 0, "result");
                                        $total_mobile = mysql_result($get_mobile, 0, "result");
                                        $total_tab = mysql_result($get_tab, 0, "result");

                                        $com_percent = $mobile_percent = $tab_percent = 0;

                                        if ($total_com > 0) {
                                            $com_percent = number_format(($total_com / ($total_com + $total_mobile + $total_tab)) * 100, 0);
                                        }

                                        if ($total_mobile > 0) {
                                            $mobile_percent = number_format(($total_mobile / ($total_com + $total_mobile + $total_tab)) * 100, 0);
                                        }

                                        if ($total_tab > 0) {
                                            $tab_percent = number_format(($total_tab / ($total_com + $total_mobile + $total_tab)) * 100, 0);
                                        }


                                        $com_chk = $mobile_chk = $tab_chk = "";

                                        $com_img = "checkbox_yellow_no_checked";
                                        $mobile_img = "checkbox_black_no_checked";
                                        $tab_img = "checkbox_bright_no_checked";

                                        $check_com = mysql_query("select count(*) as result from tbl_answer where question_id='" . $q['id'] . "' and fb_id='" . $_SESSION['fb_id'] . "' and answer='C'");
                                        if (mysql_result($check_com, 0, "result") > 0) {
                                            $com_chk = "checked='checked'";
                                            $com_img = "checkbox_yellow_checked";
                                        }

                                        $check_mobile = mysql_query("select count(*) as result from tbl_answer where question_id='" . $q['id'] . "' and fb_id='" . $_SESSION['fb_id'] . "' and answer='M'");
                                        if (mysql_result($check_mobile, 0, "result") > 0) {
                                            $mobile_chk = "checked='checked'";
                                            $mobile_img = "checkbox_black_checked";
                                        }

                                        $check_tab = mysql_query("select count(*) as result from tbl_answer where question_id='" . $q['id'] . "' and fb_id='" . $_SESSION['fb_id'] . "' and answer='T'");
                                        if (mysql_result($check_tab, 0, "result") > 0) {
                                            $tab_chk = "checked='checked'";
                                            $tab_img = "checkbox_bright_checked";
                                        }

                                        $share_copy = "Devices used to access digital banking: $com_percent% Computer, $mobile_percent% Mobile Phone, $tab_percent% Tablets. goo.gl/VaGbx ";
                                        $share_copy_clean = str_replace("%", " percent", $share_copy);
                                        ?>

                                        <div style="padding-bottom:2px">
                                            <div id="question<?= $q['id'] ?>" data-com-percent="<?= $com_percent ?>" data-mobile-percent="<?= $mobile_percent ?>" data-tab-percent="<?= $tab_percent ?>"></div> 
                                            <table width="100%" height="100%"  cellpadding="0" cellspacing="0" style="background-color:#f1f1f1">
                                                <tr>
                                                    <td style="vertical-align: top;padding-right: 10px;padding-top:6px" colspan="2" >
                                                        <a href="javascript:share_twitter_poll_check('<?= $share_copy_clean ?>','<?= $q['id'] ?>')"><img src="images/btn_twitter.png" style="float:right;margin-right: 2px" border="0"></a>                                        
                                                        <a href="javascript:streamPublishPollCheck('<?= $q['id'] ?>', '<?= str_replace("'", "\\'", FACEBOOK_APP_NAME) ?>', '')" ><img src="images/btn_facebook.png" style="float:right;margin-right: 2px" border="0"></a>   

                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" style="vertical-align: top;padding-top:5px" >
                                                        <table width="90%" align="center">
                                                            <Td style="vertical-align: top"><b><?= $no ?>. </b></td>
                                                            <td align="left"><?= $q['question'] ?></td>
                                                        </table>
                                                    </td>
                                                </tr>
                                                <tr >
                                                    <td style="vertical-align: middle;padding-left: 10px" height="65">
                                                        <div id="divChart<?= $q['id'] ?>" style="width: 140px; height: 80px;"></div>

                                                    </td>
                                                    <td width="120" style="float:right;display: block;vertical-align: middle;padding-top:20px;padding-left: 5px">
                                                        <?
                                                        if ($is_voted == 0) {
                                                            ?>
                                                            <table>
                                                                <tr align="left">
                                                                    <td><input type="checkbox" name="checkBox<?= $q['id'] ?>[]" value="C" id="checkC"  ></td>
                                                                    <td><label for="checkC"><font class="poll_option">Computer</font></label></td>
                                                                </tr>
                                                                <tr align="left">
                                                                    <td><input type="checkbox" name="checkBox<?= $q['id'] ?>[]" value="M"  id="checkM"  ></td>
                                                                    <td><label for="checkM"><font class="poll_option">Mobile</font></label></td>
                                                                </tr>
                                                                <tr align="left">
                                                                    <td><input type="checkbox" name="checkBox<?= $q['id'] ?>[]" value="T" id="checkT"  ></td>
                                                                    <td><label for="checkT"><font class="poll_option">Tablets</font></label></td>
                                                                </tr>
                                                            </table>
                                                        <? } else { ?>
                                                            <table>
                                                                <tr>
                                                                    <td><img src="images/<?= $com_img ?>.png" style="float:left;margin-right: 4px" border="0"></td>
                                                                    <td><label for="checkC"><font class="poll_option">Computer</font></label></td>
                                                                </tr>
                                                                <tr>
                                                                    <td><img src="images/<?= $mobile_img ?>.png" style="float:left;margin-right: 4px" border="0"></td>
                                                                    <td><label for="checkM"><font class="poll_option">Mobile</font></label></td>
                                                                </tr>
                                                                <tr>
                                                                    <td><img src="images/<?= $tab_img ?>.png" style="float:left;margin-right: 4px" border="0"></td>
                                                                    <td><label for="checkT"><font class="poll_option">Tablets</font></label></td>
                                                                </tr>
                                                            </table>

                                                        <? } ?>

                                                    </td>
                                                </tr>
                                                <Tr>
                                                    <Td style="height:10px">&nbsp;</td>
                                                </tr>

                                            </table>
                                        </div>

                                        <script>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

                                            $("#checkC").imageTick({ 
                                                tick_image_path: "images/checkbox_yellow_checked.png", 
                                                no_tick_image_path: "images/checkbox_yellow_no_checked.png"
                                            });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                            $("#checkM").imageTick({ 
                                                tick_image_path: "images/checkbox_black_checked.png", 
                                                no_tick_image_path: "images/checkbox_black_no_checked.png"
                                            });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                            $("#checkT").imageTick({ 
                                                tick_image_path: "images/checkbox_bright_checked.png", 
                                                no_tick_image_path: "images/checkbox_bright_no_checked.png"
                                            });
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

            <? if ($total_com == 0 && $total_mobile == 0 && $total_tab == 0) { ?>  
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
                    var data = [$.gchart.series('2004', [0,0])];

                    data[0].color= ['#f9be20','#000000'];

                    $('#divChart<?= $q['id'] ?>').gchart({type: 'pie', series: data, 

                        backgroundColor : 'transparent',
                        pieOrientation : 180                                                                                                        
                    });                                                                                                                                     

            <? } else { ?>
                    var data = [$.gchart.series('2004', [<?= $total_com ?>, <?= $total_mobile ?>,<?= $total_tab ?>])];
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                    data[0].color= ['<?= CHART_COLOR_COM ?>', '<?= CHART_COLOR_MOBILE ?>','<?= CHART_COLOR_TAB ?>'];
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                    $('#divChart<?= $q['id'] ?>').gchart({type: 'pie', series: data, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                        dataLabels: ['<?= $com_percent ?>%','<?= $mobile_percent ?>%','<?= $tab_percent ?>%'],
                        backgroundColor : 'transparent',
                        pieOrientation : 180                                                                                                        
                    });                                                                                                                                     
            <? } ?>                                                                                                                                                                                                                                                                           
                                        </script>


                                    <? } $no++;
                                } ?>


                                <script type="text/javascript" id="sourcecode">
                                    $(function()
                                    {
                                        $('.scroll-pane').jScrollPane();
                                        $('.scroll-pane-arrows').jScrollPane(
                                        {
                                            showArrows: true,
                                            horizontalGutter: 10,
                                            autoReinitialise : true
                                        }
                                    );
                                    });
                                </script>
                                <?
                                if ($is_voted == 0) {
                                    ?>
                                    <table width="100%"  cellpadding="0" cellspacing="0" style="background-color:#f1f1f1">
                                        <td style="height:60px;text-align: center;background-color:#fec832">

                                            <div id="errMsg" ></div>
                                            <input type="submit" value="Submit Your Poll" name="btnsubmit"></td>

                                    </table>
                                <? } ?>
                            </form>
                        </td>
                </table>
            </td>

        </tr>
        <Tr>
            <td style="vertical-align: top;height:100%">
                <?
                if (preg_match('/Chrome/i', $_SERVER['HTTP_USER_AGENT'])) {
                    if ($is_voted == 1) {
                        $height = '650';
                    } else {
                        $height = '710';
                    }
                } elseif (preg_match('/MSIE/i', $_SERVER['HTTP_USER_AGENT'])) {
                    if ($is_voted == 1) {
                        $height = '624';
                    } else {
                        $height = '684';
                    }
                } else {
                    if ($is_voted == 1) {
                        $height = '648';
                    } else {
                        $height = '708';
                    }
                }
                ?>
                <table width="100%" style="vertical-align: top;height:<?= $height ?>px; " cellpadding="0" cellspacing="0">    
                    <tr>
                        <td height="50" bgcolor="#fec832" style="padding-left:20px" align="left">
                            <img src="images/title_shareyourviews.png">
                        </td>
                    </tr>
                    <tr>

                        <Td width="100%" style="border:1px solid #f5f5f5;background-color:#f1f1f1;padding-left:20px;vertical-align: top;height:<?= $height ?>px" >
                            <style type="text/css" id="page-css">

                                .scroll-view
                                {
                                    width : 100%;

                                    height: <?= $height ?>px;                                    
                                    overflow: auto;

                                }


                            </style>
                            <div class="scroll-view" >
                                <table width="100%" cellpadding="0" cellspacing="0">
                                    <?
                                    $get_question = mysql_query("select * from tbl_view_question order by created_datetime desc");

                                    $no = mysql_num_rows($get_question);
                                    while ($q = mysql_fetch_assoc($get_question)) {
                                        ?>
                                        <tr>
                                            <td style="padding-top:10px">

                                                <font><?= $q['question'] ?></font>

                                            </td>

                                        </tr>
                                        <tr>
                                            <Td style="text-align: right">
                                                <font style="color:#6e6e6e;font-size:12px"><?= date("M j", strtotime($q['created_datetime'])) ?> at <?= date("g:i a", strtotime($q['created_datetime'])) ?></font>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><div class="fb-comments" data-href="http://www.maybankapps.com/fb-app/whats-your-take/fb-app/share_view.php?question_id=<?= $q['id'] ?>" data-num-posts="2" data-width="430"></div>
                                                <br> <br>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="background:url(images/divider_h.jpg) repeat-x center;" height="30">&nbsp;</td>
                                        </tr>

                                        <?
                                        $no--;
                                    }
                                    ?>
                                </table>
                            </div>
                            <script>
                                $(function()
                                {
                                    $('.scroll-view').jScrollPane(
                                    {
                                        autoReinitialise: true
                                                                                                                                                                                                                                                                                                            
                                    }
                                );
                                });
                            </script>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>


    </table>
    <?
    include_once 'includes/footer.php';
} else {


    echo "<script type='text/javascript'>top.location.href = '" . FACEBOOK_PAGE_TAB_URL . "';</script>";
}
?>